package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 执行关联查询
 */
public class Demo6 {
    public static void main(String[] args) {
        ResultSet rs = null;
        try (Connection conn = DBUtil.getConnection();){
            Statement statement = conn.createStatement();
            String sql = "SELECT c.name,c.floor,t.name,t.salary,t.title " +
                         "FROM class c " +
                         "JOIN teacher t ON c.teacher_id=t.id ";
            rs = statement.executeQuery(sql);
        while(rs.next()){
            String cName = rs.getString("c.name");
            int cFloor = rs.getInt("c.floor");
            String tName = rs.getString("t.name");
            int tSalary = rs.getInt("t.salary");
            String tTitle = rs.getString("t.title");
            System.out.println(cName+" "+cFloor+" "+tName+" "+tSalary+" "+tTitle+" ");
        }
        } catch (SQLException e) {
            e.printStackTrace();
            }
    }
}
